<?php

namespace App\Model;


use Illuminate\Http\Request;

class UserFeedback extends BaseModel
{
    protected $table = 'user_feedback';
    public $timestamps = false;
    private $fields = ['*'];
    
    public function getCreateTimestampAttribute($value){
        if(!$value) return 0;
        return date('Y-m-d H:i:s', $value);
    }
    
    public function getList(Request $request){
        $limit = $request->input('limit',10);
        $page = $request->input('page', 1);
        $uuid = $request->input('uuid', '');
        $nickname = $request->input('nickname', '');
        $content = $request->input('fe_content', '');
        $status = $request->input('fe_status');
        
        $query = new UserFeedback();
    
        if($content) $query = $query->where('fe_content','like', "%{$content}%");
        if(isset($status)) $query = $query->where('fe_status','=', $status);
    
        $query->whereHas('user',function ($query) use ($uuid, $nickname){
            $query->select('user_id');
            if($uuid) $query->where(['uuid' => $uuid]);
            if($nickname) $query->where('nickname','like',"%{$nickname}%");
        })->with(['user:user_id,uuid,nickname'])
            ->paginate($limit,$this->fields,'page',$page);
    }
    
    public function user(){
        return $this->belongsTo(Number::class,'user_id','user_id');
    }

    /**
     * 更改审核状态
     * @param $params
     * @return bool|mixed|string
     */
    public function ChangeStatus($params)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/freedback/change', $params, 'json', 'POST');
    }
}
